<?php
//use JPush\Client;
require_once 'Excels/PHPExcel.php';
require_once 'Excels/PHPExcel/IOFactory.php';

class Excels
{
    public function test($file)
    {
        $objReader = PHPExcel_IOFactory::createReader('Excel5');//use excel2007 for 2007 format
        //接收存在缓存中的excel表格
        $filename    = $file['tmp_name'];
        $objPHPExcel = $objReader->load($filename); //$filename可以是上传的表格，或者是指定的表格
        $sheet       = $objPHPExcel->getSheet(0);
        $highestRow  = $sheet->getHighestRow(); // 取得总行数
        // $highestColumn = $sheet->getHighestColumn(); // 取得总列数
        $newExcel = [];
        for ($j = 2; $j <= $highestRow; $j++) {
            $newExcel[$j]['nickname']      = $objPHPExcel->getActiveSheet()->getCell('A' . $j)->getValue();  //昵称
            $newExcel[$j]['phone']         = (string)$objPHPExcel->getActiveSheet()->getCell("B" . $j)->getValue(); //手机号
            $newExcel[$j]['referer_phone'] = (string)$objPHPExcel->getActiveSheet()->getCell("C" . $j)->getValue();//上级手机号码
        }
        return $newExcel;
    }

    public function testFile($file)
    {
        $objReader = PHPExcel_IOFactory::createReader('Excel5');//use excel2007 for 2007 format
        //接收存在缓存中的excel表格
        $filename    = $file['tmp_name'];
        $objPHPExcel = $objReader->load($filename); //$filename可以是上传的表格，或者是指定的表格
        $sheet       = $objPHPExcel->getSheet(0);
        $highestRow  = $sheet->getHighestRow(); // 取得总行数
        // $highestColumn = $sheet->getHighestColumn(); // 取得总列数
        $newExcel = [];

        for ($j = 2; $j <= $highestRow; $j++) {
            $newExcel[$j]['id']           = $objPHPExcel->getActiveSheet()->getCell('A' . $j)->getValue();  //昵称
            $newExcel[$j]['product_name'] = $objPHPExcel->getActiveSheet()->getCell("B" . $j)->getValue(); //手机号
            $newExcel[$j]['province']     = $objPHPExcel->getActiveSheet()->getCell("C" . $j)->getValue();//上级手机号码
            $newExcel[$j]['operators']    = $objPHPExcel->getActiveSheet()->getCell("D" . $j)->getValue();//上级手机号码
            $newExcel[$j]['face_value']   = $objPHPExcel->getActiveSheet()->getCell("E" . $j)->getValue();//上级手机号码
            $newExcel[$j]['price']        = $objPHPExcel->getActiveSheet()->getCell("F" . $j)->getValue();//上级手机号码
            $newExcel[$j]['discount']     = $objPHPExcel->getActiveSheet()->getCell("G" . $j)->getValue();//上级手机号码
            $newExcel[$j]['state']        = $objPHPExcel->getActiveSheet()->getCell("H" . $j)->getValue();//上级手机号码
        }
        return $newExcel;
    }

}
